/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦]
 * 
 * https://zhiqim.org/project/zhiqim_framework/zhiqim_httpd.htm
 *
 * Zhiqim Httpd is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.httpd;

import org.zhiqim.kernel.model.maps.HashMapSO;

/**
 * HTTP会话接口定义
 *
 * @version v1.0.0 @author zouzhigang 2016-7-15 新建与整理
 */
public interface HttpSession
{
    /************************************************************************************/
    //会话刷新 & 失效
    /************************************************************************************/
    
    /** 会话刷入持久层，非HashSession的如保存到远端或数据库或文件的 */
    public void flush();
    
    /** 会话失效 */
    public void invalidate();
    
    /************************************************************************************/
    //用于业务浸入式更改sessionId（注：谨慎使用），HttpResponse会oldSessionId进行处理
    /************************************************************************************/
    
    public void setNewSessionId(String newSessionId);
    
    public String getOldSessionId();
    
    public void clearOldSessionId();
    
    /************************************************************************************/
    //获取参数判断值
    /************************************************************************************/
    
    public HttpContext getContext();
    
    public String getId();
    
    public boolean isNew();
    
    public String getUserIp();
    
    public String getUserAgent();
    
    public int getMaxInactiveInterval();
    
    public long getCreated();
    
    public String getCreateTime();
    
    public long getLastAccessed();
    
    public String getLastAccessTime();
    
    public long getRemainSecond();
    
    public long getRemainMinute();
    
    public long[] getRemainTime();
    
    public String getRemainTimeDesc();
    
    /**********************************************/
    //读写关联到HttpSession中attribute列表
    /**********************************************/
    
    public Object removeAttribute(String name);
    
    /** 设置属性，List<T>和MapSV<V>会报错提示增加泛型类 */
    public void setAttribute(String name, Object value);
    
    /** 设置属性值为List<T>和MapSV<V>时，指定T/V的泛型类 */
    public void setAttribute(String name, Object value, Class<?> genericClass);
    
    public HashMapSO getAttributes();
    
    public Object getAttribute(String name);
    
    public boolean hasAttribute(String name);
    
    public Object getAttribute(String name, Object defaultValue);
    
    public String getAttributeString(String name);
    
    public String getAttributeString(String name, String defaultValue);
    
    public int getAttributeInt(String name);
    
    public int getAttributeInt(String name, int defaultValue);
    
    public long getAttributeLong(String name);
    
    public long getAttributeLong(String name, long defaultValue);
    
    public boolean getAttributeBoolean(String name, boolean defaultValue);
    
    /**********************************************/
    //SessionUser相关
    /**********************************************/    
    
    /** 判断会话中是否有用户信息 */
    public boolean hasSessionUser();
    
    /** 获取会话用户信息中用户类，多个时抛异常 */
    public HttpSessionUser getSessionUser();
    
    /** 获取会话用户名称，多个时抛异常 */
    public String getSessionName();
    
    /** 绑定会话用户信息 */
    public boolean bindSessionUser(HttpSessionUser sessionUser);
    
    /** 解绑会话用户信息 */
    public boolean unbindSessionUser();
    
    /** 判断会话中是否有用户信息且指定的用户类 */
    public <T extends HttpSessionUser> boolean hasSessionUser(Class<T> clazz);
    
    /** 获取会话用户信息且指定的用户类 */
    public <T extends HttpSessionUser> T getSessionUser(Class<T> clazz);
}
